package com.hqyj.manager.service.serviceimpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hqyj.manager.service.OrderService;
import com.hqyj.mapper.OrderItemMapper;
import com.hqyj.mapper.OrderMapper;
import com.hqyj.pojo.Order;
import com.hqyj.pojo.OrderItem;
import com.hqyj.tmall.service.OrderItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Service
public class OrderServiceimpl implements OrderService {

    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private OrderItemMapper orderItemMapper;

    @Override
    public PageInfo<Order> findAllOrder(Integer currentPage,Integer pageSize,String inputName) {
        PageHelper.startPage(currentPage,pageSize);
        List<Order> allOrder = orderMapper.findAllOrder(inputName);
        //pagehelper内部计算总共有多少页
        PageInfo<Order> pageInfo = new PageInfo<>(allOrder);
        return pageInfo;
    }

    @Override
    @Transactional
    public Integer deleteOrderById(Integer orderId) {
        Integer result = orderMapper.deleteOrderById(orderId);
        return result;
    }

    @Override
    public Integer deleteSomeByIds(String oIds) {
        String[] split = oIds.split(",");
        List<String> oIdsList = Arrays.asList(split);
        Integer integer = orderMapper.deleteSomeByIds(oIdsList);
        return integer;
    }

    @Override
    public List<Order> queryOrderById(Integer oId) {
        List<Order> orderList = orderMapper.queryOrderById(oId);
        return orderList;
    }

    @Override
    @Transactional
    public Integer updateOrderById(Order order) {
        Integer integer = orderMapper.updateOrderById(order);
        return integer;
    }

    @Override
    public OrderItem selectByProductId(Integer productId) {
        OrderItem orderItem = orderItemMapper.selectByProductId(productId);
        return orderItem;
    }

    @Override
    public Integer deleteOrderItemById(Integer productId) {
        Integer integer = orderItemMapper.deleteOrderItemById(productId);
        return integer;
    }

    @Override
    public int addOneByOrder(Order order) {
        int a=orderMapper.addOneByOrder(order);
        //int i = this.orderMapper.insertSelective(order);
        return a;
    }


}
